import 'package:flutter/material.dart';
import 'package:vista/features/auth/views/login_view.dart';
import 'package:vista/features/auth/views/register_view.dart';
import 'package:vista/features/home/views/home_view.dart';
import 'package:vista/features/challenge/views/challenge_detail_view.dart';
import 'package:vista/features/challenge/views/theme_challenge_list_view.dart';
import 'package:vista/features/inspiration/views/inspiration_detail_view.dart';
import 'package:vista/features/skills/views/skills_class_view.dart';
import 'package:vista/features/skills/views/video_player_view.dart';
import 'package:vista/features/moment/views/moment_detail_view.dart';
import 'package:vista/features/community/views/community_view.dart';
import 'package:vista/features/community/views/photography_detail_view.dart';
import 'package:vista/features/community/views/image_detail_view.dart';
import 'package:vista/features/main/views/navigation_hub.dart';
import 'package:vista/features/message/views/chat_view.dart';
import 'package:vista/features/message/views/friends_list_view.dart';
import 'package:vista/features/message/views/group_chat_view.dart';
import 'package:vista/features/message/views/video_call_view.dart';
import 'package:vista/features/profile/views/edit_profile_view.dart';
import 'package:vista/features/profile/views/other_profile_view.dart';
import 'package:vista/features/profile/views/settings_view.dart';
import 'package:vista/features/post/view/publish_post_view.dart';
import 'package:vista/features/splash/views/splash_view.dart';

/// 路由路径
class Routes {
  static const String splash = '/splash';
  static const String login = '/login';
  static const String register = '/register';
  static const String home = '/home';
  static const String main = '/main';
  static const String friendsList = '/friends-list';
  static const String chat = '/chat';
  static const String groupChat = '/group-chat';
  static const String videoCall = '/video-call';
  static const String inspirationDetail = '/inspiration-detail';
  static const String themeChallengeList = '/theme-challenge-list';
  static const String challengeDetail = '/challenge-detail';
  static const String skillsClass = '/skills-class';
  static const String videoPlayer = '/video-player';
  static const String momentDetail = '/moment-detail';
  static const String community = '/community';
  static const String photographyDetail = '/photography-detail';
  static const String imageDetail = '/image-detail';
  static const String editProfile = '/edit-profile';
  static const String settings = '/settings';
  static const String publishPost = '/publish-post';
  static const String otherProfile = '/other-profile';
}

/// 路由配置
class AppRouter {
  static const String initialRoute = Routes.splash;

  /// 生成路由
  static Route<dynamic>? generateRoute(RouteSettings settings) {
    switch (settings.name) {
      case Routes.splash:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const SplashView(),
          settings: settings,
        );
      case Routes.login:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const LoginView(),
          settings: settings,
        );
      case Routes.register:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const RegisterView(),
          settings: settings,
        );
      case Routes.home:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const HomeView(),
          settings: settings,
        );
      case Routes.main:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const NavigationHub(),
          settings: settings,
        );
      case Routes.friendsList:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const FriendsListView(),
          settings: settings,
        );
      case Routes.chat:
        final args = settings.arguments as Map<String, dynamic>?;
        final otherUserId = args?['otherUserId'] as String? ?? '';
        return MaterialPageRoute<dynamic>(
          builder: (_) => ChatView(otherUserId: otherUserId),
          settings: settings,
        );
      case Routes.groupChat:
        final args = settings.arguments as Map<String, dynamic>?;
        final groupId = args?['groupId'] as String? ?? '';
        return MaterialPageRoute<dynamic>(
          builder: (_) => GroupChatView(groupId: groupId),
          settings: settings,
        );
      case Routes.videoCall:
        final args = settings.arguments as Map<String, dynamic>?;
        final otherUserId = args?['otherUserId'] as String? ?? '';
        return MaterialPageRoute<dynamic>(
          builder: (_) => VideoCallView(otherUserId: otherUserId),
          settings: settings,
        );
      case Routes.inspirationDetail:
        final args = settings.arguments as Map<String, dynamic>?;
        final inspirationId = args?['inspirationId'] as String? ?? '';
        return MaterialPageRoute<dynamic>(
          builder: (_) => InspirationDetailView(inspirationId: inspirationId),
          settings: settings,
        );
      case Routes.themeChallengeList:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const ThemeChallengeListView(),
          settings: settings,
        );
      case Routes.challengeDetail:
        final args = settings.arguments as Map<String, dynamic>?;
        final submissionId = args?['submissionId'] as String? ?? '';
        return MaterialPageRoute<dynamic>(
          builder: (_) => ChallengeDetailView(submissionId: submissionId),
          settings: settings,
        );
      case Routes.skillsClass:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const SkillsClassView(),
          settings: settings,
        );
      case Routes.videoPlayer:
        final args = settings.arguments as Map<String, dynamic>?;
        final videoId = args?['videoId'] as String? ?? '';
        return MaterialPageRoute<dynamic>(
          builder: (_) => VideoPlayerView(videoId: videoId),
          settings: settings,
        );
      case Routes.momentDetail:
        final args = settings.arguments as Map<String, dynamic>?;
        final postId = args?['postId'] as String? ?? '';
        return MaterialPageRoute<dynamic>(
          builder: (_) => MomentDetailView(postId: postId),
          settings: settings,
        );
      case Routes.community:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const CommunityView(),
          settings: settings,
        );
      case Routes.photographyDetail:
        final args = settings.arguments as Map<String, dynamic>?;
        final postId = args?['postId'] as String? ?? '';
        return MaterialPageRoute<dynamic>(
          builder: (_) => PhotographyDetailView(postId: postId),
          settings: settings,
        );
      case Routes.imageDetail:
        final args = settings.arguments as Map<String, dynamic>?;
        final postId = args?['postId'] as String? ?? '';
        return MaterialPageRoute<dynamic>(
          builder: (_) => ImageDetailView(postId: postId),
          settings: settings,
        );
      case Routes.editProfile:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const EditProfileView(),
          settings: settings,
        );
      case Routes.settings:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const SettingsView(),
          settings: settings,
        );
      case Routes.publishPost:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const PublishPostView(),
          settings: settings,
        );
      case Routes.otherProfile:
        final args = settings.arguments as Map<String, dynamic>?;
        final userId = args?['userId'] as String? ?? '';
        return MaterialPageRoute<dynamic>(
          builder: (_) => OtherProfileView(userId: userId),
          settings: settings,
        );
      default:
        return MaterialPageRoute<dynamic>(
          builder: (_) => const SplashView(),
          settings: settings,
        );
    }
  }
}
